#include"stack.hpp"

//------------------------------------------
//function about listdata     --------------
//------------------------------------------

void ListData::init()
{
    std::cin>>a;
    std::cin>>b;
}

bool ListData::operator==(ListData& comData)
{
   if(this->a==comData.a&&this->b==comData.b)
   { 
        return 1;
   }
   else {
   return 0;
   }
}

void ListData::operator=(ListData* data)
{
   this->a=data->a;
   this->b=data->b;
}


void ListData::show()
{

    std::cout<<a<<" "<<b<<"\n";
}



//------------------------------------------
//function about linkedstack  --------------
//------------------------------------------

// LinkedStackNode& LinkedStackNode::operator=(LinkedStackNode a)
// {

// }


LinkedStack::LinkedStack()
{
    delete  top;
    top=new LinkedStackNode;
}

int LinkedStack::IfEmpty()//empty return 1  
{
    if(length==0)
    {
        return 1;
    }
    else {
    return 0;
    }
}

int LinkedStack::GetLength()
{
    return length;
}

ListData& LinkedStack::GetTop()
{
    return top->data;
}

void LinkedStack::Clear()
{ 
  LinkedStackNode* p;
  if(length!=0)
  {
    p=top;
    top=top->next;
    delete p;
    length--;
  }
}

void LinkedStack::Push(ListData& pushData)
{
    //creat newnode
   LinkedStackNode* newNode=new LinkedStackNode;
   newNode->next=top;
   newNode->data=pushData;

  //change top pointer
   LinkedStackNode* tmp;
   tmp=newNode;
   newNode=top;
   top=tmp;

   length++;
}

void LinkedStack::Pop()
{
  LinkedStackNode* p;
    p=top;
    top=top->next;
    delete p;

    length--;
}

LinkedStack::~LinkedStack()
{
 LinkedStackNode* p;
  if(length!=0)
  {
    p=top;
    top=top->next;
    delete p;
  }
  delete top;
}
